/*
 * Created by JFormDesigner on Thu Jun 08 18:33:30 CST 2023
 */

package gui.user;

import dao.UserDao;
import entity.User;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 * @author Liubuzhu
 */
public class MyInfoFrame extends JFrame {
    UserDao userDao = new UserDao();
    public MyInfoFrame(String userIdTemp) throws Exception {
        initComponents(userIdTemp);
    }

    private void initComponents(String userIdTemp) throws Exception {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        label4 = new JLabel();
        label5 = new JLabel();
        userId = new JTextField();
        userId.setEditable(false);
        userName = new JTextField();
        userName.setEditable(false);
        cardBalance = new JTextField();
        cardBalance.setEditable(false);
        password = new JTextField();
        password.setEditable(false);
        identity = new JTextField();
        identity.setEditable(false);
        cancelBtn = new JButton();

        //======== this ========
        setTitle("\u4e2a\u4eba\u4fe1\u606f");
        setPreferredSize(new Dimension(535, 500));
        setVisible(true);
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        User user = userDao.login(userIdTemp);

        //---- label1 ----
        label1.setText("\u7528\u6237\u7f16\u53f7");
        label1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(label1);
        label1.setBounds(75, 45, 90, 45);

        //---- label2 ----
        label2.setText("\u7528\u6237\u540d");
        label2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(label2);
        label2.setBounds(75, 110, 90, 45);

        //---- label3 ----
        label3.setText("\u5361\u4f59\u989d");
        label3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(label3);
        label3.setBounds(75, 175, 90, 45);

        //---- label4 ----
        label4.setText("\u5bc6\u7801");
        label4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(label4);
        label4.setBounds(75, 235, 90, 45);

        //---- label5 ----
        label5.setText("\u8eab\u4efd");
        label5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(label5);
        label5.setBounds(75, 300, 90, 45);

        //---- userId ----
        userId.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(userId);
        userId.setBounds(200, 45, 230, 45);
        userId.setText(user.getUserId());

        //---- userName ----
        userName.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(userName);
        userName.setBounds(200, 110, 230, 45);
        userName.setText(user.getUserName());

        //---- cardBalance ----
        cardBalance.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(cardBalance);
        cardBalance.setBounds(200, 175, 230, 45);
        cardBalance.setText(String.valueOf(user.getCardBalance()));

        //---- password ----
        password.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(password);
        password.setBounds(200, 235, 230, 45);
        password.setText(user.getUserPassword());

        //---- identity ----
        identity.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(identity);
        identity.setBounds(200, 300, 230, 45);
        identity.setText(user.getIdentity());

        //---- cancelBtn ----
        cancelBtn.setText("\u8fd4\u56de");
        cancelBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(cancelBtn);
        cancelBtn.setBounds(315, 385, 110, 50);

        cancelBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                dispose();
                try {
                    UserMainFrame userMainFrame = new UserMainFrame(userIdTemp);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JLabel label4;
    private JLabel label5;
    private JTextField userId;
    private JTextField userName;
    private JTextField cardBalance;
    private JTextField password;
    private JTextField identity;
    private JButton cancelBtn;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
    public static void main(String[] args) throws Exception {
        MyInfoFrame myInfoFrame = new MyInfoFrame("111");
    }
}
